<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="auto">
            <el-form-item label="来源下游" prop="channelId">
                <el-select v-model="queryParams.channelId" filterable placeholder="来源下游" clearable size="small">
                    <el-option
                        v-for="item in classesList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="请求标识" prop="mki">
                <el-input
                    v-model="queryParams.mki"
                    placeholder="请输入请求标识"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="操作时间">
                <el-date-picker
                    v-model="dateRange"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :default-time="['00:00:00', '23:59:59']"
                    align="right"
                    size="small"
                    clearable
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" ref="table" :data="tableData.list">
            <el-table-column type="index" label="序号" width="55" align="center"/>
            <el-table-column label="请求标识" align="center" prop="dmpid"/>
            <el-table-column label="类型" align="center" prop="businessTypeStr" width="80">
                <template slot-scope="scope">
                    <span>{{ scope.row.businessTypeStr=='ESCALATION'?'上报':'回调' }}</span>
                </template>
            </el-table-column>
            <el-table-column label="请求IP" align="center" prop="operIp" width="150"/>
            <el-table-column label="IP归属地" align="center" prop="operLocation" width="120"/>
            <el-table-column label="耗时(ms)" align="center" prop="timeConsuming" width="80"/>
            <el-table-column label="创建时间" align="center" prop="createTimeStr" width="150"/>
            <el-table-column label="操作" align="center" width="280px" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-view"
                        @click="handleLook(scope.row)"
                    >查看
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="tableData.total>0"
            :total="tableData.total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />


        <el-dialog title="查看详情" :visible.sync="logDetailDialog.open" width="50%" :close-on-click-modal="false"
                   append-to-body>
            <json-viewer
                :value="logDetailDialog.jsonData"
                :expand-depth=3
                copyable
                boxed
                sort
            ></json-viewer>
        </el-dialog>
    </div>

</template>

<script>
    import {
        list,
        channelList
    } from "@/api/business/hailingStatistics"


    import JsonViewer from 'vue-json-viewer'

    export default {
        name: "index",
        components: {
            JsonViewer
        },
        data() {
            return {
                // 遮罩层
                loading: false,
                // 显示搜索条件
                showSearch: true,
                tableData: {
                    list: [],
                    total: 0
                },
                // 日期范围
                dateRange: [],
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                },
                classesList: [],
                logDetailDialog: {
                    open: false,
                    jsonData: null
                }
            }
        },
        created() {
            this.getChannelList();
            this.getList();
        },
        mounted() {
        },
        methods: {
            getChannelList() {
                channelList().then(response => {
                    this.classesList = response.data.list.map(item => {
                        return {
                            label: item.title,
                            value: item.id
                        }
                    })

                });
            },
            getList() {
                this.loading = true;
                let timeMap = {}
                this.addDateRange(timeMap, this.dateRange)
                Object.keys(timeMap.params).map(key => {
                    this.queryParams[key] = timeMap.params[key]
                })
                list(this.queryParams).then(response => {
                    if(response.data){
                        this.tableData.list = response.data.data;
                        this.tableData.total = response.data.count;
                    }
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            handleLook(row) {
                this.logDetailDialog.open = true
                this.logDetailDialog.jsonData = row;
            },
        }

    }
</script>

<style scoped>

</style>
